require.config({
    baseUrl:"./modules",
    paths:{
        jq:"../libs/jquery",
        cookie:"../libs/cookie",
        load:"list_load",
        render:"render_details",
        setLocalStorage:"setLocalStorage_list",
        BigImg:"BigImg_details",
    }
})

require(["jq","cookie","load","render","setLocalStorage","BigImg",],function(_,cookie,load,render,setLocalStorage,BigImg,){
    const tbody = document.querySelector(".box");
    const url = "http://localhost:3000/api?type=getGoods"
    console.log(url)
    load(url).then((res)=>{
        //拿到cookie数组
        const goodsMsg = getCookie("goodsMsg") ? JSON.parse(getCookie("goodsMsg")) : []
        //渲染，cookie数组最后一个值（id）
        render(res,goodsMsg,$(".box")[0])
        console.log(goodsMsg[goodsMsg.length-1].id);
        //事件委托，添加购物车


        $(".box").on("click",".details-l-r-t-d2",function(){
            // console.log(1)
            
            if(localStorage.getItem("token") === "ok"){
            setLocalStorage(goodsMsg[goodsMsg.length-1].id)
        }else{
            if(confirm("您还未登录，是否前往登录？")){
                location.href="./logon.html"
            }
        }
        })
        //放大镜
        new BigImg();
    })
})